﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.HIS.FrameWork.Repository.Nhb;
using Demo.HIS.Infrastructure.Core;
using Demo.HIS.Infrastructure.Core.Repositories;

namespace Demo.HIS.Infrastructure.Repositories.Data
{
    public class DictionaryRepositoryImpl : RepositoryNhbImpl<Dictionary>, IDictionaryRepository
    {
        #region IDictionaryRepository 成员

        public IList<Dictionary> GetPlistByCategoryId(string id, int start, int limit, string sort, string dir, out long total)
        {
            sort = "d." + sort;
            var query = Session.CreateQuery(@"select d from Dictionary as d where d.Category.Id=:Id"
                + " order by " + sort + " " + dir)
                .SetString("Id", id)
                .SetFirstResult(start)
                .SetMaxResults(limit);

            total = Session.CreateQuery(@"select count(*) from Dictionary as d where d.Category.Id=:Id")
                .SetString("Id", id)
                .UniqueResult<long>();

            return query.List<Dictionary>();
        }

        #endregion
    }
}
